/******************************************************************************
GameConnection.h: interface for the GameConnection class.

Copyright (c) 2005 - Realtime Gaming.  All rights reserved.
******************************************************************************/

#if !defined(_GAMECONNECTION_H_)
#define _GAMECONNECTION_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "lib.h"
#include "connect.h"
#include "tracksql.h"

/******************************************************************************
Helper Structs & Defines
******************************************************************************/
#define GAMEID          13          //The game id for Keno-type games
#define GAMEID_SIZE		16
typedef char GameID[GAMEID_SIZE];


/******************************************************************************
struct _Info - Holds data about a player
******************************************************************************/
typedef struct _info
{
	String		    login;
	PID				pid;
	SESSIONID		sessionId;
	GameID		    gid;
	bool8			forMoney;
} Info, *pInfo;

/******************************************************************************
Forward Declaration
******************************************************************************/
class GameGuts;

/******************************************************************************
class GameConnection - Provides the message processing loop
                       Handles all generic message processing, passing
                       game-specific requests and information to a
                       GameGuts instance.
******************************************************************************/
class GameConnection : public Connection
{
    //Helper for specifying parent class
    typedef Connection super;

public:
    //Construction/Destruction
	GameConnection(Server*, SOCKET client);
	virtual ~GameConnection();

    //Message Buffer Manipulation
    void    msgStart();
    void    msgEnd();
    void    msgAdd(uint8 Byte);
    void    msgAdd(int8 SignedByte);
    void    msgAdd(int32 SignedLong);
    int32	msgRemove(uint8*, int32*);

	int32	encode(uint8*, uint8*, int32);
	int32	decode(uint8*, uint8*, int32);

    void    respondGameInProgress();
    void    respondBadCard(int32 len);
    void    respondInvalidBet();
    void    respondNoBalance();
    void    respondInvalid();

    //Tracker Methods
    bool8	trackGetBalance(int32 *);    
    void	trackaddBadPacket(int32 error_reason,
                              char MessageType, 
                              char *msgbuf, int32 msglen);      
    int32   trackAdjustBalance(int32 Amount);      
    bool8   trackGetPlayerLimits(int32* compFactor);
	int32	trackGetDenominations();
	int32	trackValidateLogin();
	int32	trackValidateSession();

	// CSN-7075: New Authentication
	void	trackLogoutSession();

    pInfo   getInfo() const;

private:          //Methods
    //Don't copy or assign.
    GameConnection(const GameConnection&);
    GameConnection& operator=(const GameConnection&);
    
protected:          //Methods
	bool8	getResponse();
    
    uint8*  msgGetBuf();
    void    msgReleaseBuf(int32 Amt);  

	void	sendStopMsg();
    
    void    handleUnknownMessage(int32 nMsgLen);
	void    handleANSILogin(int32 nMsgLen);
	void	handleUnicodeLogin(int32 nMsgLen);	
    void    handleLogin(int32 nMsgLen);    
    void    handleBalanceRequest(int32 nMsgLen);
    void    handleBetMessage(int32 nMsgLen);
    void    handleMultiplierMessage(int32 nMsgLen);

    void    handleSubGameMessage(int32 nMsgLen);
    
    bool8	parseAnsiCasinoLogin(int32*);
    bool8	parseUnicodeCasinoLogin(int32*);
    
    void	removeCasinoSpecific();

    void    allocateXMLTranslator( XMLTranslator** target );    // kharmon.  08-13-07.  Added for Flash XML stuff.


protected:          //Data
    GameGuts*       guts;
	int32 		    loggedOn;
    int32 		    msglen;
    uint8 		    msgbuf[OUTMAX];
    pInfo           casinoSpecific;

// [AO 2008-01-16] Refactoring for HA
private:
	bool ValidateSession();
};


#endif // !defined(_GAMECONNECTION_H_)
